package com.comp.web.webservice.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.comp.web.webservice.DemoWebservice;

import javax.jws.WebService;
import java.text.SimpleDateFormat;
import java.util.*;

@WebService(targetNamespace = "http://webservice.web.comp.com/",endpointInterface = "com.comp.web.webservice.DemoWebservice")
public class DemoWebserviceImpl implements DemoWebservice {
    public String sayHello(int id, String name) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(System.currentTimeMillis());
        Date date = c.getTime();
        Map<String,Object> objMap = new HashMap<String,Object>();
        List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
        for(int i=0;i<5;i++) {
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("id",id);
            map.put("name","张三");
            map.put("time",df.format(date));
            result.add(map);
        }
        objMap.put("totalCount",500);
        objMap.put("incField","id");
        objMap.put("incValue",789);
        objMap.put("status",0);
        objMap.put("msg","成功发送数据");
        objMap.put("data",result);
        JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(objMap));
        System.out.println("生产的数据="+itemJSONObj.toJSONString());
        return itemJSONObj.toJSONString();
    }

    public String sayGood() {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(System.currentTimeMillis());
        Date date = c.getTime();
        Map<String,Object> objMap = new HashMap<String,Object>();
        List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
        for(int i=0;i<5;i++) {
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("id",123);
            map.put("name","张三");
            map.put("time",df.format(date));
            result.add(map);
        }
        objMap.put("totalCount",500);
        objMap.put("incField","id");
        objMap.put("incValue",789);
        objMap.put("status",0);
        objMap.put("msg","成功发送数据");
        objMap.put("data",result);
        JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(objMap));
        System.out.println("生产的数据="+itemJSONObj.toJSONString());
        return itemJSONObj.toJSONString();
    }

    public String welcome(String data) {
        System.out.println("消费生产的数据="+data);
        Map<String,Object> objMap = new HashMap<String,Object>();
        objMap.put("status",0);
        objMap.put("msg","成功接收数据");
        JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(objMap));
        return itemJSONObj.toJSONString();
    }
}
